#pragma once

#include "mousetool.h"

class SClipPallette;

class BMPClipRect : public MouseTool
{
private:
	/** the mouse is moving freely, there are no clips drawn */
	static const int IDLE = 0;
	/** the mouse is drawing a box */
	static const int DRAWING = 1;
	/** the mouse is done drawing a box, which is rendering independent of mouse movement */
	static const int DONE = 2;
	/** the clip is being moved */
	static const int MOVING = 3;
	/** the clip is being resized */
	static const int RESIZING = 5;
	/** which clip edge is being resized */
	static const int EDGE_NONE = 0, EDGE_MINX = 1, EDGE_MINY = 2, EDGE_MAXX = 4, EDGE_MAXY = 8;

	//SRect m_rect;
	SPoint m_lastMousePositionUpdated;
	/** where the mouse is moving around on the image */
	SPoint m_pixel;
	/** where the rectangles corner points are on the image */
	SPoint m_pointA, m_pointB;
	/** when dragging the clip, this is the offset to keep the rectangle from the mouse */
	SPoint m_delta;
	/** the general state of the tool */
	int m_state;
	/** which clip is being resized */
	int m_edgeState;
	/** manages clips that are sent from this tool */
	SClipPallette * m_clipPallette;
public:
	static const char * NAME;
	const char * getName();
	BMPClipRect(void * a_context):MouseTool(a_context),m_state(IDLE),m_edgeState(0),m_clipPallette(0)
	{getButton()->setToggleable(true);}
	void updateCursor(const SPoint & a_mouse);
	/** enter key is checked, will add to m_clipPallette if possible */
	bool handleEvent(const SDL_Event & e);
	/** called when the mouse is pressed */
	bool pressedTool(const int & a_mouseButton);
	/** called as the mouse is dragged */
	bool draggedTool(const int & a_mouseButton);
	/** called when the mouse is released */
	bool releasedTool(const int & a_mouseButton);
	/** refresh the entire viewer then activated, so that clips can be shown */
	void activate();
	void deactivate();
	/** need to set extra area around the rectangle to be dirty to show mutability*/
	void setDirty(SDL_Surface * a_surface);
	/** updates the tool rectangle */
	void setToolRectangle(const SRect & a_rect);

	virtual void draw(SDL_Surface * a_surface);
	void setClipPallette(SClipPallette * a_clipPallette)
	{
		m_clipPallette = a_clipPallette;
	}
};